(function (w, $, undefined) {
	if (!$) {return;}

	var Str = (function () {
		var replaceParam = function (s, data){return s.replace(/{([^{]*?)}/g,function(match,key){return data[key]==null?match:data[key]})}
		var format = function (s){return replaceParam(s, [].slice.call(arguments, 1))}
		return {
			format : format,
			replaceParam : replaceParam
		};
	})();

	var CSS3 = function () {
		var o = {}, output;
		var prefix = ["-webkit-", "-moz-", "-ms-", "-o-"];
		if (typeof arguments[0] == "string") {
			o[arguments[0]] = arguments[1];
		} else {
			o = arguments[0];
		}
		for (var k in o) {
			for (var i = 0, len = prefix.length; i < len; i++) {
				o[prefix[i] + k] = o[k];
			}
		}
		return o;
	};
	
	var countDown = function (param) {
	if (!(param.dom && param.dom.length)) {
		return;
	}
    var e = {
        g: param.end ? param.end.getTime() : new Date().getTime(),
        e: param.date.getTime(),
        d: 1000 * 60 * 60 * 24,
        h: 1000 * 60 * 60,
        m: 1000 * 60,
        s: 1000,
        ms: 100
    };
    e.n = e.e - e.g;
    var r = {
        day: '0',
        hour: '0',
        minute: '00',
        second: '00',
        millisecond: '0',
        timeend: true
    };
    if (e.n > 0) {
        r.day = Math.floor(e.n / e.d);
        e.d -= r.day * e.d;
        r.hour = Math.floor(e.n / e.h);
        e.n -= r.hour * e.h;
        r.minute = Math.floor(e.n / e.m);
        e.n -= r.minute * e.m;
        r.second = Math.floor(e.n / e.s);
        e.n -= r.second * e.s;
        r.millisecond = Math.floor(e.n / e.ms);
        for (var a in r) {
            if (a == 'timeend') {
                continue
            }
            if (r[a] > 0) {
                r.timeend = false
            }
            if (r[a] < 10 && a != 'millisecond') {
                r[a] = '0' + r[a]
            } else {
                r[a] = '' + r[a]
            }
        }
    }
    param.data = r;
    param.dom.html(Str.replaceParam(param.temp, param.data));
    if (Math.floor((e.e - e.g) / 1000 <= 0) && param.callback) {
        param.callback();
        return
    }
    countDown.Timer = setTimeout(function() {
        countDown(param);
    },
    param.time || 1000);
	}
	
	var tmpl = function (data) {
    var regJs = /<%([\w\W]*?)%>/g,
    regJsExpression = /\bbreak\b|\bcase\b|\bcatch\b|\bcontinue\b|\bdefault\b|\bdelete\b|\bdo\b|\belse\b|\bfinally\b|\bfor\b|\bfunction\b|\bif\b|\breturn\b|\bswitch\b|\bthrow\b|\btry\b|\bvar\b|\bwhile\b|\bwith\b|{|}/g,
    newval = ' var r=[];\n',
    len = 0;
    var append = function(val, script) {
        return script ? (newval += val.match(regJsExpression) ? val + '\n': 'r.push(' + val + ');\n') : (newval += val != '' ? 'r.push("' + val.replace(/"/g, '\\"') + '");\n': ''),
        append
    };
    while (match = regJs.exec(data.v)) {
        append(data.v.slice(len, match.index))(match[1], true);
        len = match.index + match[0].length;
    }
    append(data.v.slice(len));
    newval += ' return r.join("");';
    var html = new Function(newval.replace(/[\n\r\t]/g, "")).apply(data.datas);
    if (data.dom) {
      data.dom.html(html);
      data.callback && data.callback();
    } else {
      return html;
    }
};

	var ani = function (o) {
		console.log(o);
		console.log(o.$el.html());
		if (!o.$el || !o.$el.length) {
			return;
		}
		var x = o.start, y, step = o.step || 2, ended, duration = o.duration || 1000;
		var ellipse = function (coordinatesX) {
			return 2 * (25 - Math.sqrt(50 * 50 - (coordinatesX - 50) * (coordinatesX - 50)) / 2 );
		}
		var fn = o.fn || ellipse;
		step = o.end > o.start ? step : -1 * step;

		var timeGap = duration / (Math.abs(o.start - o.end) / step);

		var frame = function () {
			x += step;
			ended = (step > 0 && x >= o.end) || (step < 0 && x <= o.end);
			if (ended) {
				x = o.end;
			}
			y = fn(x);
			o.$el.css({
				"left" : x + "%",
				"top" : y + "%"
			});
			if (ended) {
				o.callback && o.callback();
				return;
			}
			window.requestAnimationFrame ? window.requestAnimationFrame(frame) : setTimeout(frame, timeGap);
		}
		frame();
	};

	var Seckill = function (o) {
		o = o || {};
		this.o = $.extend(
		{
			init: function () {},
			before: function () {},
			moving: function () {},
			after: function () {}
		}, o);
		this.init();
	};

	Seckill.prototype = {
		bindEvent: function () {
			var that = this;
			var pos = {};
			
			var listOffset = that.module.product_list.offset().top;
			var itemHeight = that.module.children.product_list.eq(0).height() / that.scene[0].product.length;
			var translateY = 0;
			
			document.addEventListener("touchstart", function (ev) {
				that.o.before(that);
				pos.x1 = ev.touches[0].pageX;
				pos.y1 = ev.touches[0].pageY;
				return;
			}, false);

			document.addEventListener("touchmove", function (ev) {
				pos.x2 = ev.touches[0].pageX;
              			pos.y2 = ev.touches[0].pageY;
                			var x = pos.x2 - pos.x1;
                			var y = pos.y2 - pos.y1;				
				if (Math.abs(y) > Math.abs(x)) {
                    				that.setPos( - 100 * that.index + "%", true);
			                } else {
			                	var width = $(window).width();
			                	that.setPos(x - that.index * width + "px", false);
			                }
                
				ev.preventDefault();
				return;
			}, false);

			document.addEventListener("touchend", function (ev) {
				
				pos.x2 = ev.changedTouches[0].pageX;
				pos.y2 = ev.changedTouches[0].pageY;

				var x = pos.x2 - pos.x1;
				var y = pos.y2 - pos.y1;
				if (Math.abs(x) < 30 && Math.abs(y) < 30) {
					return;
				}
				
				if (Math.abs(y) > Math.abs(x)) {
					var listHeight = that.module.children.product_list.eq(that.index).height();
					if (listOffset + listHeight < $(window).height() - itemHeight) {
						ev.preventDefault();
						return;
					}

					if (y > 0) {
						translateY -= itemHeight * 2;
						if (translateY < itemHeight) {
							translateY = 0;
						}
					} else {
						if (translateY < listOffset) {
							translateY = listOffset;
						} else if (translateY + $(window).height() < listOffset + listHeight + itemHeight) {
							translateY += itemHeight * 2;
						}
					}
					$("#seckillContent").css(CSS3({ "transform" : "translateY(" + -1 * translateY + "px)" }));
					ev.preventDefault();
					return;
				}
				
				var width = $(window).width();
				if (Math.abs(x) < width / 4) {
					that.setPos( - 100 * that.index + "%", true);
					ev.preventDefault();
					return;
                			}

				var $el = that.module.children.ico.eq(that.index);
				var $prev = $el.prev();
				var $prev2 = $el.prev().prev();
				var $next = $el.next();
				var $next2 = $el.next().next();

				if (x > 0) {
					if (that.index == 0) {
						that.setPos( - 100 * that.index + "%", true);
						ev.preventDefault();
						return;
					}
					ani({ $el: $prev2, start: 0, end: 10 });
					$prev2.css({ "opacity" : 1 });
					ani({ $el: $prev, start: 10, end: 50 });
					ani({ $el: $el, start: 50, end: 90 });
					ani({ $el: $next, start: 90, end: 100 });
					$next.css({ "opacity" : 0 });
					that.index--;
				} else {
					if (that.index == that.scene.length - 1) {
						that.setPos( - 100 * that.index + "%", true);
						ev.preventDefault();
						return;
					}
					ani({ $el: $prev, start: 10, end: 0 });
					$prev.css({ "opacity" : 0 });
					ani({ $el: $el, start: 50, end: 10 });
					ani({ $el: $next, start: 90, end: 50 });
					ani({ $el: $next2, start: 100, end: 90 });
					$next2.css({ "opacity" : 1 });
					that.index++;
				}
				that.index = that.index <= 0 ? 0 : that.index;
				that.index = that.index == that.scene.length ? that.scene.length - 1 : that.index;

				that.index == that.scene.length - 1 && !that.loadLock && that.loadNextScene();
				
				translateY = 0;
				$("#seckillContent").css(CSS3({ "transform" : "translateY(0)" }));
				
				that.renderPage();
				ev.preventDefault();
				return;
			}, false);
		},
		setPos: function(pos, needTransition) {
		            var that = this;
		            var ani = {};
		            ani.transition = needTransition ? "all 1s ease": "none";
		            ani.transform = "translate3d(" + pos + ", 0, 0)";
		            that.module.product_list.css(CSS3(ani));
		            that.module.countdown.show().css(CSS3(ani));
		 },
		loadNextScene: function () {
			var that = this;
			
			var curNo = that.scene[that.index].sysNo;
			that.loadLock = true;
			
			var nextScene;
			$.post(webRoot+"/secKillAjax/nextData", {"curNo":curNo}, function(datas) {
				if (!datas){
					return false;
				}
				datas = JSON.parse(datas);
				nextScene = datas;
				
				var now = new Date();
				$.each(nextScene, function(k, v) {
					v.start = new Date(new Date(v.start).getTime() + 10000);
					v.end = new Date(v.end);
					if (now < v.start) {
						v.status = 1;
					} else if (now < v.end) {
						v.status = 2;
					} else {
						v.status = 0;
					}
				});
				that.scene = that.scene.concat(nextScene);
				
				that.module.ico.append(tmpl({ v : that.tmpl.ico, datas : nextScene}));
				that.module.countdown.append(tmpl({ v : that.tmpl.countdown, datas : nextScene}));
				that.module.product_list.append(tmpl({ v : that.tmpl.product_list, datas : nextScene}));
				
				that.module.children = {};
				that.module.children.ico = that.module.ico.children();
				that.module.children.countdown = that.module.countdown.children();
				that.module.children.product_list = that.module.product_list.children();
				
				that.module.children.ico.eq(that.index).next().addClass("ico_right");
				that.module.children.countdown.each(function (index) {
					$(this).css(CSS3({ "transform" : "translate3d(" + 100 * index + "%, 0, 0)" }));
				});
				
				that.module.children.product_list.each(function (index) {
					$(this).css(CSS3({ "transform" : "translate3d(" + 100 * index + "%, 0, 0)" }));
				});
				
				if (that.scene[that.scene.length - 1].status == 1) {
					countDown({ 
						dom : that.module.children.countdown.eq(that.scene.length - 1), 
						date : that.scene[that.scene.length - 1].start, 
						temp : '<em>距开始</em><span>{hour}</span><font>:</font><span>{minute}</span><font>:</font><span>{second}</span>',
						callback: function () {
							initSecKillData();
						}
					});
				} else if (that.scene[that.scene.length - 1].status == 2) {
					countDown({ 
						dom : that.module.children.countdown.eq(that.scene.length - 1), 
						date : that.scene[that.scene.length - 1].end, 
						temp : '<em>距结束</em><span>{hour}</span><font>:</font><span>{minute}</span><font>:</font><span>{second}</span>',
						callback: function () {
							initSecKillData();
						}
					});
				}
				
				that.renderPage();
				
				that.loadLock = false;
			});

		},
		initData: function () {
			var that = this;
			that.colorSet = ["#175692", "#f35b6c", "#00245a", "#630358", "#1cb484", "#f7ffe2", 
				"#e0ffdc", "#fdfce0", "#fff7f0", "#fcffea", "#ffeeee", "#ffeefd",
				"#ffffd6", "#fff2d6", "#d6f3ff", "#ffe5d6", "#fff9d6", "#ffebde", 
				"#e6ffd6", "#e3edff", "#f0e87a", "#cbe99c", "#fbd188", "#ef6848"];
			that.scene = that.o.scene;
			that.loadLock = false;

			that.index = 0;
			var hasIndex = 0;
			var now = new Date();
			$.each(that.scene, function(k, v) {
				v.start = new Date(new Date(v.start).getTime() + 10000);
				v.end = new Date(v.end);
				//     活动时间20:00-22:00                         活动时间 10:00-12:00                                                    活动时间15:00-17:00
				//k=0          that.index=0  hasIndex=2    v.status=0  本场已经结束                                                 
				//k=1                                                            v.status=2  that.index=1  hasIndex=2   距结束        
				//k=2                                                            v.status=1  距开始                                                          that.index=2    hasIndex=2

				if (now < v.start) {
					v.status = 1;
					if (hasIndex < 1) {
						that.index = k;
						hasIndex = 1;
					}
				} else if (now < v.end) {
					v.status = 2;
					if (hasIndex < 2) {
						that.index = k;
						hasIndex = 2;
					}
				} else {
					v.status = 0;
				}
			});

			that.tmpl = {};
			that.tmpl.countdown = $("#tmpl_countdown").html();
			that.tmpl.ico = $("#tmpl_ico").html();
			that.tmpl.product_list = $("#tmpl_product_list").html();
			
			that.module = {};
			that.module.ico = $("[data-module=ico]");
			that.module.countdown = $("[data-module=countdown]");
			that.module.product_list = $("[data-module=product_list]");

		},
		initPage: function () {
			var that = this;
			tmpl({ dom : that.module.ico, v : that.tmpl.ico, datas : that.scene});
			tmpl({ dom : that.module.countdown, v : that.tmpl.countdown, datas : that.scene});
			tmpl({ dom : that.module.product_list, v : that.tmpl.product_list, datas : that.scene});
			that.module.children = {};
			that.module.children.ico = that.module.ico.children();
			that.module.children.countdown = that.module.countdown.children();
			that.module.children.product_list = that.module.product_list.children();

			that.module.children.ico.eq(that.index).prev().addClass("ico_left");
			that.module.children.ico.eq(that.index).addClass("ico_center");
			that.module.children.ico.eq(that.index).next().addClass("ico_right");

			that.module.children.countdown.each(function (index) {
				$(this).css(CSS3({ "transform" : "translate3d(" + 100 * index + "%, 0, 0)" }));
			});

			that.module.children.product_list.each(function (index) {
				$(this).css(CSS3({ "transform" : "translate3d(" + 100 * index + "%, 0, 0)" }));
			});

			that.renderPage();
		},
		renderPage: function () {
			var that = this;

			//change line color
			var hour = that.module.children.ico.eq(that.index).attr("data-hour");
			var color = hour >= 5 && hour <= 21 ? "#888888" : "#eeeeee";
			$(".time_bar").css({ "border-top-color" : color });

			//position
			that.module.product_list.css("height", Math.max.apply(null, that.module.children.product_list.map(function () {
				return $(this).height();
			})));
			that.setPos(-100 * that.index + "%", true);
			//that.module.product_list.css(CSS3({ "transform" : "translate3d(" + -100 * that.index + "%, 0, 0)" }));
			//that.module.countdown.show().css(CSS3({ "transform" : "translate3d(" + -100 * that.index + "%, 0, 0)" }));
			$("#seckillContent, body, #divBody").css({ "background-color" : that.colorSet[that.module.children.ico.eq(that.index).attr("data-hour")] });

			//lazyload images when swiping
			$("[tab_lazyload]", that.module.children.product_list.eq(that.index)).each(function () {
				var src = $(this).attr("tab_lazyload");
				$(this).attr("src", src).removeAttr("tab_lazyload");
			});

			//change color of the ico when swiping
			var $el = that.module.children.ico.eq(that.index);
			var className = ["ico_ended", "ico_start", "ico_end"];
			$el.find("p").removeClass().addClass(className[that.scene[that.index].status]);
			$el.prev().find("p").removeClass().addClass("ico_ended");
			$el.next().find("p").removeClass().addClass("ico_ended");

			//change title
			if (that.scene[that.index].groupName) {
				$("#groupName").text(that.scene[that.index].groupName);
				$("#wapTop").attr("data-skName", that.scene[that.index].groupName);
			} else {
				$("#groupName").text("欢乐秒杀购");
				$("#wapTop").attr("data-skName", "欢乐秒杀购");
			}
			
			that.index != 0 ? $("#nomore_left").css({ "opacity" : 0 }) : $("#nomore_left").css({ "opacity" : 1 });
			that.index != that.scene.length - 1 ? $("#nomore_right").css({ "opacity" : 0 }) : $("#nomore_right").css({ "opacity" : 1 });

			w.scrollTo(0, 0);
		},
		initCountDown: function () {
			var that = this;
			$.each(that.scene, function (k, v) {
				if (v.status == 1) {
					countDown({ 
						dom : that.module.children.countdown.eq(k), 
						date : v.start, 
						temp : '<em>距开始</em><span>{hour}</span><font>:</font><span>{minute}</span><font>:</font><span>{second}</span>',
						callback: function () {
							initSecKillData();
						}
					});
				} else if (v.status == 2) {
					countDown({ 
						dom : that.module.children.countdown.eq(k), 
						date : v.end, 
						temp : '<em>距结束</em><span>{hour}</span><font>:</font><span>{minute}</span><font>:</font><span>{second}</span>',
						callback: function () {
							initSecKillData();
						}
					});
				}
			});
		},
		init: function () {
			var that = this;
			that.initData();
			that.initPage();
			that.initCountDown();
			that.bindEvent();
			that.o.init(that);
		}
	};

	w.Seckill = Seckill;

})(window, Zepto);

if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", function () {

		var appObj = getAppObj();
		
		if(isApp()){
			
			if (typeof(appObj.goback) == "function") {
				
				var btnLock = false;
				
				appObj.isShowAppAction("01",0);
				if (typeof(window.appjsobj) != "undefined") {
					var a=getCookie("version");
					var r=a.replace(/\"/g,'');		
					if(r >="2.1.0"){
						$("#wap_menu_show_btn").hide();
						$("#wap_menu_main").hide();
						$("#myPage").hide();
					}else{
						$("#wap_menu_show_btn").hide();
						$("#wap_menu_main").hide();
						$("#wap_buy_show_btn").show();
						$("#myPage").show();
					}
			
					
					$("#wap_buy_show_btn").click(function(e) {
						appObj.CartAction();
						return false;
					});
					
				}
				if (typeof(window.androidjsobj) != "undefined") {
					
					$("#wap_menu_show_btn").hide();
					$("#wap_menu_main").hide();
					$("#myPage").hide();
				}
				
				$("#topBack").click(function(e) {
					if (btnLock) {
						return;
					}
					btnLock = true;
					appObj.goback();
					setTimeout(function () {
						btnLock = false;
						}, 500);
				});
				$("#openShareBtn").click(function(e) {
					if (btnLock) {
						return;
					}
					btnLock = true;
					var aTitle = $("#wapTop").attr("data-skName");
					var img = "http://image.benlailife.com/wap/images/Icon120.png";
					appObj.shareAppAction(window.location.href, img, "我在 @本来生活-" + aTitle + " 极致美食，一网打尽，一起做个资深吃货吧！");
					setTimeout(function () {
						btnLock = false;
						}, 500);
				});
				
			} else {
				$("#topBack").hide();
				$("#topShare").hide();
			}
			
			$("#wap_top").show();
			
		} else {
			$("#topBack").click(function(e) {
				getBack($(this));
			});
			$("#openShareBtn").click(function(e) {
				var aTitle = $("#wapTop").attr("data-skName");
				var img = "http://image.benlailife.com/wap/images/ben.jpg";
				openShare('','我在 @本来生活 - ' + aTitle + ' 极致美食，一网打尽，一起做个资深吃货吧！', img, window.location.href);
			});
			$("#wap_top").show();
		}

		initSecKillData();
	});
}

function initSecKillData() {
	$.post(webRoot+"/secKillAjax/mainData", function(datas) {
		if (!datas){
			return false;
		}
		datas = JSON.parse(datas);
		
		for (var i=0; i < datas.length; i++) {
			var tmp = datas[i];
			if (!tmp.product) {
				tmp.product = new Array();
			}
		}
		
		new Seckill({ "scene" : datas });
	});
}





/*!
 * by zhangxinxu(.com) 2012-12-27
 * you can visit http://www.zhangxinxu.com/wordpress/?p=3855 to get more infomation
 * under MIT license
 */
var funParabola = function(element, target, options) {
	/*
	 * 网页模拟现实需要一个比例尺
	 * 如果按照1像素就是1米来算，显然不合适，因为页面动不动就几百像素
	 * 页面上，我们放两个物体，200~800像素之间，我们可以映射为现实世界的2米到8米，也就是100:1
	 * 不过，本方法没有对此有所体现，因此不必在意
	 */

	var defaults = {
		speed: 166.67, // 每帧移动的像素大小，每帧（对于大部分显示屏）大约16~17毫秒
		curvature: 0.001,  // 实际指焦点到准线的距离，你可以抽象成曲率，这里模拟扔物体的抛物线，因此是开口向下的
		progress: function() {},
		complete: function() {}
	};

	var params = {}; options = options || {};

	for (var key in defaults) {
		params[key] = options[key] || defaults[key];
	}

	var exports = {
		mark: function() { return this; },
		position: function() { return this; },
		move: function() { return this; },
		init: function() { return this; }
	};

	/* 确定移动的方式
	 * IE6-IE8 是margin位移
	 * IE9+使用transform
	 */
	var moveStyle = "margin", testDiv = document.createElement("div");
	if ("oninput" in testDiv) {
		["", "ms", "webkit"].forEach(function(prefix) {
			var transform = prefix + (prefix? "T": "t") + "ransform";
			if (transform in testDiv.style) {
				moveStyle = transform;
			}
		});
	}

	// 根据两点坐标以及曲率确定运动曲线函数（也就是确定a, b的值）
	/* 公式： y = a*x*x + b*x + c;
	 */
	var a = params.curvature, b = 0, c = 0;

	// 是否执行运动的标志量
	var flagMove = true;

	if (element && target && element.nodeType == 1 && target.nodeType == 1) {
		var rectElement = {}, rectTarget = {};

		// 移动元素的中心点位置，目标元素的中心点位置
		var centerElement = {}, centerTarget = {};

		// 目标元素的坐标位置
		var coordElement = {}, coordTarget = {};

		// 标注当前元素的坐标
		exports.mark = function() {
			if (flagMove == false) return this;
			if (typeof coordElement.x == "undefined") this.position();
			element.setAttribute("data-center", [coordElement.x, coordElement.y].join());
			target.setAttribute("data-center", [coordTarget.x, coordTarget.y].join());
			return this;
		}

		exports.position = function() {
			if (flagMove == false) return this;

			var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft,
				scrollTop = document.documentElement.scrollTop || document.body.scrollTop;

			// 初始位置
			if (moveStyle == "margin") {
				element.style.marginLeft = element.style.marginTop = "0px";
			} else {
				element.style[moveStyle] = "translate(0, 0)";
			}

			// 四边缘的坐标
			rectElement = element.getBoundingClientRect();
			rectTarget = target.getBoundingClientRect();

			// 移动元素的中心点坐标
			centerElement = {
				x: rectElement.left + (rectElement.right - rectElement.left) / 2 + scrollLeft,
				y: rectElement.top + (rectElement.bottom - rectElement.top) / 2	+ scrollTop
			};

			// 目标元素的中心点位置
			centerTarget = {
				x: rectTarget.left + (rectTarget.right - rectTarget.left) / 2 + scrollLeft,
				y: rectTarget.top + (rectTarget.bottom - rectTarget.top) / 2 + scrollTop
			};

			// 转换成相对坐标位置
			coordElement = {
				x: 0,
				y: 0
			};
			coordTarget = {
				x: -1 * (centerElement.x - centerTarget.x),
				y:  -1 * (centerElement.y - centerTarget.y)
			};

			/*
			 * 因为经过(0, 0), 因此c = 0
			 * 于是：
			 * y = a * x*x + b*x;
			 * y1 = a * x1*x1 + b*x1;
			 * y2 = a * x2*x2 + b*x2;
			 * 利用第二个坐标：
			 * b = (y2+ a*x2*x2) / x2
			 */
			// 于是
			b = (coordTarget.y - a * coordTarget.x * coordTarget.x) / coordTarget.x;

			return this;
		};

		// 按照这个曲线运动
		exports.move = function() {
			// 如果曲线运动还没有结束，不再执行新的运动
			if (flagMove == false) return this;

			var startx = 0, rate = coordTarget.x > 0? 1: -1;

			var step = function() {
				// 切线 y'=2ax+b
				var tangent = 2 * a * startx + b;
				// 下面是根据确定的移动速度，得到当前切线下x也就是水平方向移动的大小
				// 已知两点之间的距离为
				// Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
				// 因此应当是
				// Math.sqrt(△x*△x + △y*△y) = speed
				// 因为写这段代码的时候，脑子不在线，所以，根号忘记了
				// 就套用了下面的公式（导致很多小伙伴不理解，这里说声抱歉）
				// 不过对于大功能并不影响，就是这个speed参数值有些大，哈哈
				// y*y + x*x = speed
				// (tangent * x)^2 + x*x = speed
				// x = Math.sqr(speed / (tangent * tangent + 1));
				startx = startx + rate * Math.sqrt(params.speed / (tangent * tangent + 1));

				// 防止过界
				if ((rate == 1 && startx > coordTarget.x) || (rate == -1 && startx < coordTarget.x)) {
					startx = coordTarget.x;
				}
				var x = startx, y = a * x * x + b * x;

				// 标记当前位置，这里有测试使用的嫌疑，实际使用可以将这一行注释
				element.setAttribute("data-center", [Math.round(x), Math.round(y)].join());

				// x, y目前是坐标，需要转换成定位的像素值
				if (moveStyle == "margin") {
					element.style.marginLeft = x + "px";
					element.style.marginTop = y + "px";
				} else {
					element.style[moveStyle] = "translate("+ [x + "px", y + "px"].join() +")";
				}

				if (startx !== coordTarget.x) {
					params.progress(x, y);
					window.requestAnimationFrame(step);
				} else {
					// 运动结束，回调执行
					params.complete();
					flagMove = true;
				}
			};
			window.requestAnimationFrame(step);
			flagMove = false;

			return this;
		};

		// 初始化方法
		exports.init = function() {
			this.position().mark().move();
		};
	}

	return exports;
};

/*! requestAnimationFrame.js
 * by zhangxinxu 2013-09-30
 */
(function() {
	var lastTime = 0;
	var vendors = ['webkit', 'moz'];
	for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
		window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
		window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||    // name has changed in Webkit
			window[vendors[x] + 'CancelRequestAnimationFrame'];
	}

	if (!window.requestAnimationFrame) {
		window.requestAnimationFrame = function(callback, element) {
			var currTime = new Date().getTime();
			var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
			var id = window.setTimeout(function() {
				callback(currTime + timeToCall);
			}, timeToCall);
			lastTime = currTime + timeToCall;
			return id;
		};
	}
	if (!window.cancelAnimationFrame) {
		window.cancelAnimationFrame = function(id) {
			clearTimeout(id);
		};
	}
}());